﻿using Bot.Dynamics365.Enum;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Bot.Dynamics365
{
    public static class Utils
    {
        public static string ConnectUrl(string host, string url)
        {
            return $"{host}{url}";
        }

        public static HttpRequestMessage BuildHttpRequestMessage(string host, string url, EnumHttpMethod method)
        {
            var request = new HttpRequestMessage(new HttpMethod(method.ToString()), Utils.ConnectUrl(host, url));
            return request;
        }

        public static HttpRequestMessage BuildHttpRequestMessage(string url, EnumHttpMethod method)
        {
            var request = new HttpRequestMessage(new HttpMethod(method.ToString()), url);
            return request;
        } 
        
        public static string CapitalLettersWithSpaces(string text)
        {
            return System.Text.RegularExpressions.Regex.Replace(text, "[A-Z]", " $0");
        }

        public static string GetFileExtension(string base64String)
        {
            var data = base64String.Substring(0, 5);

            switch (data.ToUpper())
            {
                case "IVBOR":
                    return "png";
                case "/9J/4":
                    return "jpg";
                case "AAAAF":
                    return "mp4";
                case "JVBER":
                    return "pdf";
                case "AAABA":
                    return "ico";
                case "UMFYI":
                    return "rar";
                case "E1XYD":
                    return "rtf";
                case "U1PKC":
                    return "txt";
                case "MQOWM":
                case "77U/M":
                    return "srt";
                default:
                    return string.Empty;
            }
        }
    }
}
